<?php
//后台管理登录控制器
	namespace Application\Admin\Controller;
	use KJ\Controller;
	use Application\Admin\Model\User;
	use KJ\Captcha;
	class Login extends Controller{
		public function index(){
			$this->loginName = isset($_COOKIE['loginName']) ? $_COOKIE['loginName'] : '';
			$this->loginPass = isset($_COOKIE['loginPass']) ? $_COOKIE['loginPass'] : '';
			$this->layouts = FALSE;
			$this->render();
		}
		public function login(){
			$verifyCode = $_POST['verification'];
			$userName = $_POST['name'];
			$userPass = $_POST['password'];
			$md5Pass = md5($userPass);
			if($_SESSION['verifycode'] == $verifyCode){
				$user = new User();
				$user = $user -> where("username = '$userName' and userpass = '$md5Pass'")->select();
				if(empty($user)){
					echo "<script>alert('用户名密码错误');window.location.href='index.php?m=admin&c=login&a=index';</script>";
					return;
				}
				if(isset($_POST['remember_me'])){
					setcookie('loginName',$userName,time()+20,'/');
					setcookie('loginPass',$userPass,time()+20,'/');
				}else{
					setcookie('loginName','',time()-1,'/');
					setcookie('loginPass','',time()-1,'/');
				}
				$_SESSION['loginName'] = $userName;
				echo "<script>window.location.href='index.php?m=admin&c=index&a=index';</script>";
			}else{
				echo "<script>alert('验证码错误');window.history.back(-1);</script>";
			}

			
		}
		public function verify(){
			$captcha = new Captcha();
			$captcha -> font = './KJ/fonts/msyhbd.ttf';
			$captcha -> doimg();
		}
	}
?>